package com.smart.car.message;

import com.smart.car.message.config.DataSourceProxyAutoConfiguration;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.sql.DataSource;

@EnableFeignClients
@EnableScheduling   //开启定时任务注解
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")  //分布式下的定时任务锁，默认30s
@Slf4j
@EnableDiscoveryClient
@Import({DataSourceProxyAutoConfiguration.class})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableBinding({Sink.class})
public class SmartcarMessageApplication {

    public static void main(String[] args) {
        //设置禁用mq日志
        System.setProperty("rocketmq.client.log.loadconfig", "false");
        SpringApplication.run(SmartcarMessageApplication.class, args);
        log.info("message服务正在运行...");
    }



    //基于jdbc提供的lock provider(锁机制)
    @Bean
    public LockProvider lockProvider(DataSource dataSource) {
        return new JdbcTemplateLockProvider(dataSource);
    }


}
